
# read values passed from the outside
param ($url, $value)
$key = "TemplateLibraryConnector.HubUrl"


# -----------------------------------------------------------------
# Set a value for a property in a web app
# -----------------------------------------------------------------
function Set-HubKey($url, $key, $value)
{
	$webApp = Get-SPWebApplication | Where-Object {$_.Url -eq $url}
	if($webApp -ne $null)
	{
		$webApp.Properties[$key] = $value
		$webApp.Update()
		Write-Host "Template hub changed from '$($webApp.Properties[$key])' to '$($value)' for web app '$($url)'." 
	}
	else
	{
	Write-Host "Could not find web application $($url)."
	}
}


if($url -ne $null -And $value -ne $null)
{
	Set-HubKey $url $key $value
}
else
{
	Write-Host " "
	Write-Host "Please use this utility to define a site collection as your template hub."
	Write-Host "The template hub site collection can be located in any web app in the farm."
	Write-Host "The template hub will be common for the entire web application"
	Write-Host " "
	Write-Host " .\definehub.ps1 ""<WebAppUrl>"" ""<TemplateHubUrl>"" e.g.:"
	Write-Host " "
	Write-Host " .\definehub.ps1 ""http://webApp/"" ""http://webApp/sites/templatehub/"" "
	Write-Host " "
	Write-Host "To stop using a template hub in your web app, pass in a blank hub string:"
	Write-Host " "
	Write-Host " .\definehub.ps1 ""http://webApp/"" """" "
	Write-Host " "
}